/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vps;

import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.Properties;

/**
 *
 * @author Hue
 */
public class InitVps implements Task {
    private Properties params;

    @Override
    public void setProperties(Properties params) {
        this.params = params;
    }

    @Override
    public void run() {
        try {
            openTeamViewer();
            Thread.sleep(3000);
            openTeamViewer();
            
            Robot robot = new Robot();
            keyPress(robot, KeyEvent.VK_DOWN);
            keyPress(robot, KeyEvent.VK_ENTER);
            keyPress(robot, KeyEvent.VK_TAB);
            keyPress(robot, KeyEvent.VK_SPACE);
            keyPress(robot, KeyEvent.VK_ENTER);
            
            new Screenshot().run();
            
            Thread.sleep(90000);
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    private void keyPress(Robot robot, int key) throws Exception {
        robot.keyPress(key);
        Thread.sleep(50);
        robot.keyRelease(key);
        Thread.sleep(500);
    }
    
    public void openTeamViewer() {
        try {
            String command = params.getProperty("command");
            Runtime.getRuntime().exec(command);
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
}
